<template>
  <div class="common-page f-c">
    <BackPage title="投资项目办件信息" />
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="办件编号：">
          <el-input v-model="searchParams.approvalItemid" clearable />
        </el-form-item>
        <el-form-item label="办理状态：">
          <el-select v-model="searchParams.status" clearable>
            <el-option v-for="item in options" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="事项名称：">
          <el-input v-model="searchParams.event" clearable />
        </el-form-item>
        <el-form-item label="项目代码：">
          <el-input v-model="searchParams.projectCode" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-form inline>
      <el-form-item>
        <el-button type="primary" @click="onExport">导出</el-button>
      </el-form-item>
    </el-form>

    <div class="table-box f-g">
      <el-table
        v-loading="loading"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="120px">
          <template slot-scope="scope">
            <el-button type="text" @click="onEdit(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <NoteDetail ref="NoteDetailRef" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http_event } from '@/api'
import { handleStatus } from '@/dict'
import NoteDetail from '@/views/note/detail'
import { exportFile } from '@/utils/request'

export default {
  name: 'Index',
  components: { NoteDetail },
  mixins: [crud],
  data() {
    return {
      request: http_event,
      searchParams: {
        approvalItemid: '',
        approvalCode: '',
        event: '',
        status: ''
      },
      options: [
        { value: 'A0502', name: '办结（不通过）' },
        { value: 'A0501', name: '办结（通过）' },
        { value: 'A0503', name: '办结（其他）' },
        { value: 'A0200', name: '办理中（部门做出受理决定）' },
        { value: 'A0101 ', name: '已退件' },
        { value: 'A0100 ', name: '已接件' },
        { value: 'A0300 ', name: '不予受理' }
      ],
      options2: handleStatus,
      columns: [
        { prop: 'approvalItemid', label: '办件编号' },
        { prop: 'projectCode', label: '项目代码' },
        { prop: 'event', label: '审批事项名称' },
        { prop: 'handDepartment', label: '审批部门名称' },
        { prop: 'divisionCode', label: '所属区划代码' },
        { prop: 'statusName', label: '当前办理状态' },
        { prop: 'handleTime', label: '当前状态的时间' }
      ],
      tableData: [
      ]
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.statusName = this.options.find(item => item.value == el.status)?.name
      })
    },
    onEdit(item) {
      this.$refs.NoteDetailRef.open(item)
    },
    onExport() {
      exportFile('exportData/downloadIrsEvent?approvalItemid=' + this.searchParams.approvalItemid + 
      '&approvalCode=' + this.searchParams.approvalCode + '&event=' + this.searchParams.event +
      '&status=' + this.searchParams.status
      )
    }
  }
}
</script>

<style scoped lang="scss">
</style>
